﻿using System;

namespace Hsenl {
    public abstract class ADataVersionHandler : IDataVersionHandler {
        public abstract Type TargetType { get; }

        public abstract int InputVersion { get; }

        public abstract int OutputVersion { get; }

        public abstract IDataVersionUpdatable Handle(IDataVersionUpdatable dataUpdatable);
    }

    public abstract class ADataVersionHandler<T> : ADataVersionHandler where T : IDataVersionUpdatable {
        public override Type TargetType => typeof(T);

        public override IDataVersionUpdatable Handle(IDataVersionUpdatable dataUpdatable) {
            if (dataUpdatable is not T input)
                return dataUpdatable;

            return this.Handle(input);
        }

        public abstract T Handle(T input);
    }
}